home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 23
/
AACD 23.iso
/
AACD
/
Games
/
dynAMIte
/
Developer
/
C
/
dynbot.c
< prev
Wrap
C/C++ Source or Header
|
2001-06-24
|
2KB
|
118 lines
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <exec/semaphores.h>
#include <dos/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include "dynamite.h"
int
main()
{
struct dynamitesemaphore *dynasema;
struct player *ourplayer;
BOOL done = FALSE,
delay;
/* check if dynamite is running */
srand (time(NULL));
Forbid(); /* try to find the semaphore */
dynasema=(struct dynamitesemaphore *)FindSemaphore("dynAMIte.0");
Permit();
if(dynasema)
{
printf("dynAMIte is started\n");
ObtainSemaphore(&dynasema->sema); /* lock it */
/*
increase opencount to tell dynamite that you are using the
semaphore. dynamite will remove semaphore only if opencnt is
0 at its end
*/
dynasema->opencnt++;
ReleaseSemaphore(&dynasema->sema); /* release it */
printf("Clients using the semaphore: %ld\n",dynasema->opencnt);
while (!done)
{
if(CheckSignal(SIGBREAKF_CTRL_C))
{
done=TRUE;
}
else
{
delay=TRUE;
ObtainSemaphore(&dynasema->sema);
if(dynasema->quit)
{
/* dynamite wants to quit, so we do dynamite a favour */
printf("dynAMIte is about to quit...\n");
done=TRUE;
}
else
{
/* if a game is running */
if(dynasema->gamerunning>=GAME_GAME)
{
/* and player is no observer */
if(dynasema->thisplayer<8)
{
delay=FALSE;
ourplayer=dynasema->players[dynasema->thisplayer];
/* and our player is alive */
if(ourplayer->dead)
{
/* do your AI stuff */
dynasema->walk= rand()%DIR_UP+1;
}
}
}
}
ReleaseSemaphore(&dynasema->sema);
if(delay)
{
/* no game is running */
/* do a small delay to let the cpu do other things :( */
Delay(10);
}
}
}
ObtainSemaphore(&dynasema->sema);
/*
decrease opencount to tell dynamite that you no longer need
the semaphore.
dynamite will remove the semaphore only if opencnt is
0 at the end
*/
dynasema->opencnt--;
ReleaseSemaphore(&dynasema->sema);
}
else
{
printf("dynamite is not running\n");
}
return EXIT_SUCCESS;
}